﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using UI.ParentForm;
using Components;
using UI.Lib;

namespace UI.BaseResource
{
    public partial class FrmPsn0a00 : BaseMain
    {
        FrmPsn0a00Edit edit = null;

        public FrmPsn0a00(string modulecode, string action)
            : base(modulecode, action)
        {
            InitializeComponent();

            SetToolButton(); //设置工具栏按钮
        }

        /// <summary>
        /// 设置工具栏按钮
        /// </summary>
        private void SetToolButton()
        {
            //将打印配货但按钮加入在发货按钮之前
            this.tspTop.Items.Add(base.CreateToolBtn("T", "公司设置", new EventHandler(OnSettingBtnClick)));
        }

        protected void OnSettingBtnClick(object o, EventArgs e)
        {
            DataGridViewRow row = this.GetSelectedRow();
            if (null == row) return;

            FrmPsn0a00Setting frm = new FrmPsn0a00Setting("T", GetTitleStyle(this.Text, "公司设置"),
                Validation.ToString(row.Cells["comcode"].Value), Validation.ToString(row.Cells["comname"].Value));

            frm.ShowDialog();
        }

        protected override void OnAddClick(ToolStripButton btn)
        {
            edit = new FrmPsn0a00Edit("A", GetTitleStyle(this.Text, btn.Text), "");
            edit.ShowDialog();
            if (edit.IsReload) base.BindGrid();
        }

        protected override void OnEditClick(ToolStripButton btn, DataGridViewRow row)
        {
            OpenEdit("M", btn.Text, Validation.ToString(row.Cells["comcode"].Value));
        }

        protected override void OnDeleteClick(ToolStripButton btn, DataGridViewRow row)
        {
            OpenEdit("D", btn.Text, Validation.ToString(row.Cells["comcode"].Value));
        }

        protected override void OnViewClick(ToolStripButton btn, DataGridViewRow row)
        {
            OpenEdit("V", btn.Text, Validation.ToString(row.Cells["comcode"].Value));
        }

        private void OpenEdit(string action, string btnText, string code)
        {
            edit = new FrmPsn0a00Edit(action, GetTitleStyle(this.Text, btnText), code);
            edit.ShowDialog();
            if (edit.IsReload) base.BindGrid();
        }

        protected override void UpdatePager(UI.Common.Pager pager)
        {
            if (!Context.IsSuperUser)
            {
                pager.StrWhere = "comcode = '" + Context.realComcode + "'";
            }
        }
    }
}
